package com.kly.test

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.pm.ApplicationInfo
import com.kly.module_base.extension.isMainProcess
import com.kly.module_base.utils.LogUtil
import com.kly.test.init_model.InitNetworkModel
import com.tencent.mmkv.MMKV

class App : Application() {

    companion object {
        @JvmStatic @SuppressLint("StaticFieldLeak")
        var context: Context? = null
        @SuppressLint("StaticFieldLeak")
        private var instance: App? = null

        fun getInstance() = instance!!
    }

    override fun onCreate() {
        super.onCreate()
        context = this
        instance = this
        MMKV.initialize(this)
        val isDebuggable = 0 != applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
        LogUtil.init(isDebuggable)
        if (isMainProcess()){
            sdkInits().forEach{
                it.init(this)
            }
        }
    }

    override fun attachBaseContext(base: Context) {
        context = this
        super.attachBaseContext(base)
    }

    private fun sdkInits() = listOf(
        InitNetworkModel()
    )
}